#include <string>
#include <vector>
#include<cmath>
#include<list>
#include<iostream>

using namespace std;

class Solution 
{

    private:

        list<int> changed_line;
        vector<int> P;
        int the_size_of_P = 0;

        void HandleVector(vector<int>& A)
        {
            int sum = 0;

            for (auto it : A)
            {
                P.push_back(sum + it);
                sum += it;
                ++the_size_of_P;
            }

        }



    public:
    
        int shortestSubarray(vector<int>& A, int K) 
        {
            int ans = the_size_of_P + 1;
            HandleVector(A);
            for (int i = 0;i <= the_size_of_P;i++)
            {
                while(!changed_line.empty() && P[i] <= P[changed_line.back()])
                    changed_line.pop_back();
                
                while(!changed_line.empty() && P[i] >= P[changed_line.front()] + K)
                {
                    ans = (ans>(i - changed_line.front()))?(i - changed_line.front()):ans;
                    changed_line.pop_front();
                }

                changed_line.push_back(i);

            }

            // cout<< ans<(the_size_of_P + 1)?ans : -1 << endl;
            return (ans<(the_size_of_P + 1))?ans : -1;

        }
    
};


int main()
{
    vector<int> A{1,2,3,-1,-1,3,4,5,6,-4,-1,3,3,3,4};
    int k = 4;
    Solution B;
    cout<<B.shortestSubarray(A,k)<<endl;
    return 0;
}